package com.hspedu.single_;

/**
 * 饿汉式单例模式 练习
 * 步骤
 * 1.构造器私有化
 * 2.直接把该类进行实例化，且是静态属性
 * 3.先外提供一个访问权限为public且是静态的类，返回值为该对象
 */
public class SingleTest01 {
    public static void main(String[] args) {
        System.out.println(A02.n1);
        A02 a01 = A02.getInstance();
        A02 a02 = A02.getInstance();
        System.out.println(a01);
        System.out.println(a01 == a02);
    }
}

class A02 {
    public static int n1 = 10;
    private String name;
    private static A02 a02 = new A02("小黄");

    private A02(String name) {
        System.out.println("构造器被调用~~");
        this.name = name;
    }

    public static A02 getInstance() {
        return a02;
    }

    @Override
    public String toString() {
        return "A02{" +
                "name='" + name + '\'' +
                '}';
    }
}